package com.summit.exam.servlet;


import com.summit.exam.dbdao.StudentDao;
import com.summit.exam.entity.StudentBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

public class SelectStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        String name = req.getParameter("name");

        StudentDao studentService = new StudentDao();
        ArrayList<StudentBean> allStudent;

        if (name != "") {
            allStudent = studentService.queryStudent(name);
        } else {
            allStudent = studentService.queryAllStudent();
        }

        req.setAttribute("allStudent", allStudent);
        req.getRequestDispatcher( "/ExamSystem/techweb/StudentManage.jsp").forward(req, resp);
    }
}